/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.editpart;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ElementImport;
import org.eclipse.uml2.uml.NamedElement;

import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.figures.StringFigure;
import com.cea.papyrus.core.utils.Debug;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;

/**
 * 
 */
public class LinkNameDisplayEditPart extends GraphNodeWithSemanticEditPart implements IUMLElementEditPart{
	
	/**
	 * The element type accepted by the associated list model.
	 * If null, any type is accepted.
	 */
	protected org.eclipse.uml2.uml.Element element;
	
	/**
	 * 
	 */
	protected int channel=14;
	
	/**
	 * Create a FeatureList EditPart accepting any kind from drag and drop.
	 * 
	 * @param modelManager 
	 * @param graphnode 
	 */

	public LinkNameDisplayEditPart(GraphNode graphnode, ModelManager modelManager) {
		super(graphnode,modelManager);
		Debug.debug(this,"create NameDisplayEditPart()",channel);
		this.element = null;
	}

	/**
	 * Create a FeatureList EditPart accepting specified type from drag and drop.
	 * Create a ListEditPart for a List accepting only specified element.
	 * 
	 * @param element 
	 * @param modelManager 
	 * @param elementType 	 * @param graphnode 
	 */
	public LinkNameDisplayEditPart(GraphNode graphnode,org.eclipse.uml2.uml.Element element,ModelManager modelManager) {
		super(graphnode,modelManager);
		Debug.debug(this,"create NameDisplayEditPart("+ element+")",channel);
		this.element = element;
	}

	/**
	 * 
	 */
	@Override
	protected void createEditPolicies(){
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableEditPolicy());
	}

	// TODO remove this unused method
	/**
	 * 
	 */
	@Deprecated
	public void forceRegisterVisuals(){
		this.registerVisuals();
	}


	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.editpart.GraphNodeWithSemanticEditPart#createFigure()
	 */
	/**
	 * 
	 * 
	 * @return 
	 */
	@Override
	protected IFigure createFigure() {
		
		if(element instanceof NamedElement){
			return new StringFigure(((NamedElement)element).getName());} else {
			return new StringFigure("");
		}
	}
	
	
	
	
	/**
	 * 
	 * 
	 * @return 
	 */
	@Override
	public  Element getUmlElement(){
		return element;
	} 
	
	
	 
	/**
	 * 
	 * 
	 * @return 
	 */
	@Override
	public boolean isElementImport(){
		return (element instanceof ElementImport);
	}
	
	
	 
	/**
	 * 
	 * 
	 * @return 
	 */
	@Override
	public ElementImport getElementImport(){
		if (element instanceof ElementImport){
			return (ElementImport)element;
		}
		return null;
	}
	
	/**
	 * 
	 */
	@Override
	protected void refreshVisuals() {
		StringFigure f = (StringFigure)getFigure();
		if(element instanceof NamedElement){
			f.setText(((NamedElement)element).getName());}
		f.setVisible(this.isVisible());
	}
	
	
    /**
     * Return false.
     * This method is used in {@link com.cea.papyrus.core.editpart.LayoutEditPolicy} in order to
     * know how to compute the coordinate of a added part.
     * @TODO move this method to more appropriate place. 
     * @return
     */
	@Override
    public boolean needRelativeTranslationForAddCommand()
    {
        return false;
    }

}
